package com.huifaapp.mall.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.huifaapp.mall.R;
import com.huifaapp.mall.bean.SpecialGddodsBean;
import com.huifaapp.mall.view.NumberSelectView;

import java.util.List;

/**
 * Created by duanyu on 2018/1/24.
 */

public class Tnall_specialAdapter extends RecyclerView.Adapter<Tnall_specialAdapter.MyViewHolder> implements  View.OnClickListener{
    private List<SpecialGddodsBean.DataBean.ListBean>list;
    private Context context;

    public Tnall_specialAdapter(List<SpecialGddodsBean.DataBean.ListBean> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View recyclerViewItem = LayoutInflater.from(parent.getContext()).inflate(R.layout.itme_tmall_special, parent, false);
        recyclerViewItem.setOnClickListener(this);
        return new MyViewHolder(recyclerViewItem);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        Glide.with(context).load(list.get(position).getMainImageUrl()).into(holder.tmall_special_mainImageUrl);
        holder.tmall_special_goodsName.setText(list.get(position).getGoodsName());
        holder.tmall_special_price.setText(list.get(position).getPrice());
        holder.tmall_special_conPrice.setText(list.get(position).getConPrice());
        holder.itemView.setTag(position);
    }

    @Override
    public int getItemCount() {
        return list.size();
    }


    @Override
    public void onClick(View v) {
        if (mMyItemclickListener != null) {
            mMyItemclickListener.itemclick(v, (Integer) v.getTag());
        }
    }

    public interface MyItemclickListener {
        void itemclick(View view, int position);
    }
    public MyItemclickListener mMyItemclickListener;

    public void setmMyItemclickListener(MyItemclickListener mMyItemclickListener) {
        this.mMyItemclickListener = mMyItemclickListener;
    }
    class MyViewHolder extends RecyclerView.ViewHolder {

        private final ImageView tmall_special_mainImageUrl;
        private final TextView tmall_special_goodsName;
        private final TextView tmall_special_conPrice;
        private final TextView tmall_special_price;

        public MyViewHolder(View itemView) {
            super(itemView);
            tmall_special_mainImageUrl = (ImageView) itemView.findViewById(R.id.tmall_special_mainImageUrl);
            tmall_special_goodsName = (TextView) itemView.findViewById(R.id.tmall_special_goodsName);
            tmall_special_price = (TextView) itemView.findViewById(R.id.tmall_special_Price);
            tmall_special_conPrice = (TextView) itemView.findViewById(R.id.tmall_special_coPrice);

        }
    }
}
